<?php

namespace App\Http\Controllers;

use App\Models\Zuowen;
use Illuminate\Http\Request;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Validator as FacadesValidator;

class ZuowenController extends BaseController
{
    use ValidatesRequests;

    public function info(Request $request){

        $zuowen_id = request()->input("zuowen_id");

        $validator = FacadesValidator::make($request->all(), [
            'zuowen_id' => 'required',
        ]);

        if ($validator->fails()) {
            return resFail(null, "参数错误", ERROR_CODE);
        }

        $zuowen = Zuowen::query()->find($zuowen_id);

        if(!$zuowen){
            return resFail(null, "记录不存在或已被删除", -1);
        }
        return resSucc($zuowen, "作文详情");
    }

    public function list(Request $request){
        $limit = $request->limit ?? 10;
        $zuowens = Zuowen::paginate($limit);
        return resSucc(formatPage($zuowens), "作文列表");
    }
}
